package com.jeeplus.juhe;

import java.security.MessageDigest;

/**
 * Created on 2016/10/14
 *
 * @author Saligia
 */
public class Md5Util {
 
    private Md5Util() {
    }
 
    public static String MD5_16(String s) {
        String md5 = MD5(s);
        return md5 == null ? null : md5.substring(8, 24);
    }
 
    public static String MD5(String s) {
        char[] hexDigits = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
 
        try {
            byte[] e = s.getBytes();
            MessageDigest mdInst = MessageDigest.getInstance("MD5");
            mdInst.update(e);
            byte[] md = mdInst.digest();
            int j = md.length;
            char[] str = new char[j * 2];
            int k = 0;
 
            for (byte byte0 : md) {
                str[k++] = hexDigits[byte0 >>> 4 & 15];
                str[k++] = hexDigits[byte0 & 15];
            }
 
            return new String(str);
        } catch (Exception var10) {
            var10.printStackTrace();
            return null;
        }
    }
 
}